package com.ruoyi.my.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.WebTakeTime;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.my.domain.GrTuanInfo;
import com.ruoyi.my.service.IGrTuanInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 线报Controller
 *
 * @author ruoyi
 * @date 2022-01-03
 */
@RestController
@RequestMapping("/my/info")
public class GrTuanInfoController extends BaseController {
    @Autowired
    private IGrTuanInfoService grTuanInfoService;

/**
 * 查询线报列表
 */
@WebTakeTime
@PreAuthorize("@ss.hasPermi('my:info:list')")
@GetMapping("/list")
    public TableDataInfo list(GrTuanInfo grTuanInfo) {
        startPage();
        List<GrTuanInfo> list = grTuanInfoService.selectGrTuanInfoList(grTuanInfo);
        return getDataTable(list);
    }

    /**
     * 导出线报列表
     */
    @PreAuthorize("@ss.hasPermi('my:info:export')")
    @Log(title = "线报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrTuanInfo grTuanInfo) {
        List<GrTuanInfo> list = grTuanInfoService.selectGrTuanInfoList(grTuanInfo);
        ExcelUtil<GrTuanInfo> util = new ExcelUtil<GrTuanInfo>(GrTuanInfo. class);
        util.exportExcel(response, list, "线报数据");
    }

    /**
     * 获取线报详细信息
     */
    @PreAuthorize("@ss.hasPermi('my:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(grTuanInfoService.selectGrTuanInfoById(id));
    }

    /**
     * 新增线报
     */
    @WebTakeTime
    @PreAuthorize("@ss.hasPermi('my:info:add')")
    @Log(title = "线报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrTuanInfo grTuanInfo) {
        return toAjax(grTuanInfoService.insertGrTuanInfo(grTuanInfo));
    }

    /**
     * 修改线报
     */
    @PreAuthorize("@ss.hasPermi('my:info:edit')")
    @Log(title = "线报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrTuanInfo grTuanInfo) {
        return toAjax(grTuanInfoService.updateGrTuanInfo(grTuanInfo));
    }

    /**
     * 删除线报
     */
    @WebTakeTime
    @PreAuthorize("@ss.hasPermi('my:info:remove')")
    @Log(title = "线报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(grTuanInfoService.deleteGrTuanInfoByIds(ids));
    }
}
